package com.sky.loveshop.config;

import feign.RequestInterceptor;
import feign.RequestTemplate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;

/**
 * @author xcy
 * @version V1.0
 * @description 对feign调用接口进行入参拦截并记录日志
 * @date 2024/11/9 17:30
 */
@Slf4j
@Configuration
public class CustomFeignInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate requestTemplate) {
        // 打印请求方法
        log.info("FeignRequest Method: {}", requestTemplate.method());
        // 打印请求URL
        log.info("FeignRequest URL: {}", requestTemplate.url());
        // 打印请求头
        log.info("FeignRequest Headers: {}", requestTemplate.headers());
        // 打印请求体（如果存在）
        if (requestTemplate.body() != null) {
            String requestBody = new String(requestTemplate.body());
            log.info("FeignRequest Body 请求: {}", requestBody);
        }
    }
}
